﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Data;
using System.Drawing;
using System.Diagnostics;
using System.Drawing.Drawing2D;

using FCNS.KeepMoney.Configuration;
using FCNS.KeepMoney.UI;
using FCNS.KeepMoneyLibrary.Data;
using FCNS.KeepMoney.Util;

namespace FCNS.KeepMoney.Forms
{
    public partial class MainForm
    {
        private void InitGtd()
        {
            toolMenuMode.Text = "GTD";
            toolMenuFilter.Visible = false;
            toolMenuImport.Enabled = false;

            gtdView.Dock = DockStyle.Fill;
            listViewGtd1.Dock = DockStyle.Fill;
            gtdView.Visible = true;
            listViewGtd1.Visible = true;

            treeViewExGroup.Visible = false;
            listViewEntry.Visible = false;

            panelRight.Visible = false;

            splitContainerCenter.Panel2Collapsed = true;
        }

        private void ShowGtd()
        {
            listViewGtd1.Items.Clear();
            foreach (GtdGroupField gf in GtdGroupField.GetGtdGroupField)
            {
                ListViewItemGtd item = new ListViewItemGtd();
                item.Tag = gf;
                item.Text = gf.Name;
                item.Color = gf.ColorBorder;
                item.Checked = gf.Checked;
                item.GroupField =gf;

                listViewGtd1.Items.Add(item);
            }

            listViewGtd1.UpdateList();

            foreach (ListViewItemGtd item in listViewGtd1.Items)
                if (item.Checked)
                    gtdView.ModifiGtdGroups(item.GroupField, true);

            gtdView.UpdateGtdView(true);
        }


        private void OnGtdGroupSelectedChanged(object sender, EventArgs e)
        {
            gtdView.SelectedGtdData = listViewGtd1.Selected.GroupField;
        }

        private void OnGtdGroupEdit(ListViewItemGtd item)
        {
          item.GroupField.Checked = item.Checked;
            item.GroupField.Name = item.Text;
            item.GroupField.Color = item.GroupField.Color;

            Program.SaveKMD = true;
        }

        private void OnGtdGroupCheckedChanged(ListViewItemGtd item)
        {
            item.GroupField.Checked = item.Checked;
            gtdView.ModifiGtdGroups(item.GroupField, item.Checked);
            gtdView.UpdateGtdView(true);

            Program.SaveKMD = true;
        }


        void OnGtdViewDefaultChangedTask()
        {
            listViewGtd1.UpdateList();
        }
             

        void gtdSort_Click(object sender, EventArgs e)
        {
            configGtd.SortByDate = (((ToolStripMenuItem)sender).Name == "menuItemGtdEndDate");
            UpdateUI_GtdMenu();
        }

        private void OnGtdGroup_DragEnter(object sender, DragEventArgs e)
        {
            e.Effect = DragDropEffects.Copy;
        }

        private void OnGtdGroup_DragDrop(object sender, DragEventArgs e)
        {
            ListViewItemGtd item = listViewGtd1.GetItem(e.X - this.Left, e.Y - listViewGtd1.PointToScreen(new Point(0, 0)).Y - listViewGtd1.TitleHeight);
            if (item != null)
            {
                ((GtdEntryField)e.Data.GetData(typeof(GtdEntryField))).GtdGroup = item.GroupField;
                gtdView.UpdateGtdView(true);
                listViewGtd1.UpdateList();
            }
        }
    }
}
